package com.yilin.platform.controller;

import com.yilin.platform.base_core.application.BaseController;
import com.yilin.platform.base_core.application.PageData;
import com.yilin.platform.base_core.application.ReturnData;
import com.yilin.platform.base_core.interceptor.EncryptInterceptor;
import com.yilin.platform.entity.wlhy.TmsRootData;
import com.yilin.platform.service.ITmsDataService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/platform/tms/")
public class TmsController extends BaseController {

    @Resource
    private ITmsDataService tmsDataService;

    /**
     * 获取未上传数据包
     */
    @PostMapping(value = "getWaitUploadTmsDataPage")
    @EncryptInterceptor
    public ReturnData<PageData<TmsRootData>> getWaitUploadTmsDataPage(String ipcType, TmsRootData.Status status,String identification, Integer page, Integer limit) {
        PageData<TmsRootData> waitUploadTmsDataList = tmsDataService.getWaitUploadTmsDataPage(ipcType, status,identification,page,limit);
        return jsonView(SUCCESS_CODE, "获取成功", waitUploadTmsDataList);
    }

    /**
     * 同步下载数据
     */
    @PostMapping(value = "syncTmsDataList")
    @EncryptInterceptor
    public ReturnData<Integer> syncTmsDataList() {
        List<TmsRootData> tmsRootData = tmsDataService.syncUploadTmsDataList(getLoginUser());
        return jsonView(SUCCESS_CODE, "同步成功",tmsRootData.size());
    }

    /**
     * 手动提交选择数据
     */
    @PostMapping(value = "postTmsDataByIds")
    @EncryptInterceptor
    public ReturnData<List<TmsRootData>> postTmsDataByIds(String[] ids) {
        tmsDataService.postTmsDataByIds(getLoginUser(),ids);
        return jsonView(SUCCESS_CODE, "获取成功");
    }

    /**
     * 一键上送所有未提交数据
     */
    @PostMapping(value = "postAllTmsDataList")
    @EncryptInterceptor
    public ReturnData<List<TmsRootData>> postAllTmsDataList() {
        tmsDataService.postAllTmsDataList(getLoginUser());
        return jsonView(SUCCESS_CODE, "获取成功");
    }

    /**
     * 上送所有失败数据
     */
    @PostMapping(value = "postFailTmsDataList")
    @EncryptInterceptor
    public ReturnData<List<TmsRootData>> postFailTmsDataList() {
        tmsDataService.postFailTmsDataList(getLoginUser());
        return jsonView(SUCCESS_CODE, "获取成功");
    }

}
